package com.gcb.common.enums;

import lombok.Getter;

import java.util.Arrays;
import java.util.Optional;

/**
 * 项目类型
 */
@Getter
public enum ProjectTypeEnum {
    DIG_SAND(1, "挖沙"),
    DREDGING(2, "清淤"),
    CONSTRUCTION(3, "施工"),
    TRANSPORTATION(4, "运输");

    private final Integer code;
    private final String info;

    ProjectTypeEnum(Integer code, String info) {
        this.code = code;
        this.info = info;
    }


    public static String getInfo(String type) {
        return Optional.ofNullable(of(Integer.parseInt(type)))
                .map(ProjectTypeEnum::getInfo)
                .orElse("");
    }

    public static String getInfo(Integer type) {
        return Optional.ofNullable(of(type))
                .map(ProjectTypeEnum::getInfo)
                .orElse("");
    }

    public static ProjectTypeEnum of(Integer code) {
        Optional<ProjectTypeEnum> first = Arrays.stream(ProjectTypeEnum.values()).filter(v -> v.getCode().equals(code)).findFirst();
        return first.orElse(null);
    }
}
